package com.server.commons.file.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.net.url.UrlPath;
import com.server.common.code.utils.DateUtil;
import lombok.Getter;
import lombok.Setter;

import java.nio.charset.StandardCharsets;
import java.util.List;

@Getter
@Setter
public class FilePathAnalysis {
    private String bucketName;
    private String userCode;
    //功能名
    private String businessName;
    private String year;
    private String month;
    private String day;
    private String fileCode;
    private String suffix;

    public void setFileFullPath(String url){
        List<String> segments = UrlPath.of(url, StandardCharsets.UTF_8).getSegments();
        String bucketName = CollUtil.get(segments, 3);
        setBucketName(bucketName);

        String userCode = CollUtil.get(segments, 4);
        setUserCode(userCode);

        String businessName = CollUtil.get(segments, 5);
        setBusinessName(businessName);

        String year = CollUtil.get(segments, 6);
        setYear(year);

        String month = CollUtil.get(segments, 7);
        setMonth(month);

        String day = CollUtil.get(segments, 8);
        setDay(day);

        String fileName = CollUtil.get(segments, 9);
        if(fileName.contains(".")){
            setFileCode(fileName.split("\\.")[0]);
            setSuffix(fileName.split("\\.")[1]);
        }

    }
}
